package com.study.juc2;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author study
 * @version 1.0
 * @date 2020/9/22 21:22
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //一个 task只会调用一次
        FutureTask<Integer> task = new FutureTask(new MyThread());

        new Thread(task).start();

        Integer result = task.get();
        System.out.println(result);


    }
}

class MyThread implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        System.out.println("***come in here");
        return 1024;
    }
}
